package com.cy.store.configure;

import com.cy.store.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/** 处理拦截器的注册 */
@Configuration //加载并注册当前的拦截器
public class LoginInterceptorConfigure implements WebMvcConfigurer {

    /** 创建自定义的拦截器对象 */
    HandlerInterceptor interceptor = new LoginInterceptor();
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置白名单存放一个list集合
        List<String> patterns = new ArrayList<>();
        patterns.add("/bootstrap3/**");
        patterns.add("/css/**");
        patterns.add("/images/**");
        patterns.add("/js/**");
        patterns.add("/web/register.html");
        patterns.add("/web/login.html");
        patterns.add("/web/product.html");
        patterns.add("/index.html");
        patterns.add("/user/reg");
        patterns.add("/user/login");
        patterns.add("/district/**");
        patterns.add("/product/list_hot");
        //完成拦截器的注册
        registry.addInterceptor(interceptor)
                .addPathPatterns("/**")//表示要拦截的url
                .excludePathPatterns(patterns);//白名单
    }
}
